package com.gitee.wsl.collections.map

import com.gitee.wsl.base.Objects.equals
import kotlin.jvm.JvmOverloads

/**
 * An implementation of java.util.Map that is optimal (in terms of both size
 * and speed) for very small sets of data but still works excellently with
 * large sets of data.  This implementation is not thread-safe.
 *
 *
 * The InflatableMap implementation switches at runtime between several different
 * sub-implementations for storing the Map of objects, described here:
 *
 *
 *  1. "empty map" - a map that contains no data;
 *  1. "single entry" - a reference directly to a single map entry
 *  1. "Object[]" - a reference to an array of entries; the item limit for
 * this implementation is determined by the THRESHOLD constant;
 *  1. "delegation" - for more than THRESHOLD items, a map is created to
 * delegate the map management to; sub-classes can override the default
 * delegation class (java.util.HashMap) by overriding the factory method
 * instantiateMap.
 *
 *
 *
 * The InflatableMap implementation supports the null key value.
 *
 * @author cp 06/29/99
 */
//class InflatableMap<K, V> : AbstractMap<K, V>, Cloneable{
//    // ----- constructors ---------------------------------------------------
//    /**
//     * Construct a InflatableMap.
//     */
//    constructor()
//
//    /**
//     * Construct a InflatableMap with the same mappings as the given map.
//     *
//     * @param map the map whose mappings are to be placed in this map.
//     */
//    constructor(map: Map< K,  V>) {
//        putAll(map)
//    }
//
//
//    // ----- Map interface --------------------------------------------------
//    /**
//     * Returns <tt>true</tt> if this map contains no key-value mappings.
//     *
//     * @return <tt>true</tt> if this map contains no key-value mappings
//     */
//    override fun isEmpty(): Boolean {
//        return m_nImpl == I_EMPTY
//    }
//
//    /**
//     * Returns the number of key-value mappings in this map.
//     *
//     * @return the number of key-value mappings in this map
//     */
//    override val size: Int
//        get() = when (m_nImpl) {
//            I_EMPTY ->  0
//
//            I_SINGLE ->  1
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 ->  m_nImpl - I_ARRAY_1 + 1
//
//            I_OTHER ->  (m_oContents as Map<K,V>).size
//
//            else -> throw IllegalStateException()
//        }
//
//
//    /**
//     * Returns <tt>true</tt> if this map contains a mapping for the specified
//     * key.
//     *
//     * @return <tt>true</tt> if this map contains a mapping for the specified
//     * key, <tt>false</tt> otherwise.
//     */
//    override fun containsKey(oKey:K): Boolean {
//        when (m_nImpl) {
//            I_EMPTY -> return false
//
//            I_SINGLE -> {
//                val oKeyEntry: Any? = (m_oContents as Map.Entry<K,V>).key
//                return equals<Any?>(oKey, oKeyEntry)
//            }
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> {
//                // "Entry[]" implementation
//                val aEntry= m_oContents as Array<Map.Entry<K,V>>
//                val c = m_nImpl - I_ARRAY_1 + 1
//                return indexOf(aEntry, c, oKey) >= 0
//            }
//
//            I_OTHER -> return (m_oContents as Map<K,V>).containsKey(oKey)
//
//            else -> throw IllegalStateException()
//        }
//    }
//
//    /**
//     * Returns the value to which this map maps the specified key.
//     *
//     * @param oKey  the key object
//     *
//     * @return the value to which this map maps the specified key,
//     * or null if the map contains no mapping for this key
//     */
//    override fun get(oKey: K): V? {
//        when (m_nImpl) {
//            I_EMPTY -> return null
//
//            I_SINGLE -> {
//                val entry = m_oContents as Map.Entry<K,V>
//                val entryKey = entry.key
//                return if (equals<Any?>(oKey, entryKey)) entry.value else null
//            }
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> {
//                // "Entry[]" implementation
//                val aEntry = m_oContents as Array<Map.Entry<K, V>>
//                val c = m_nImpl - I_ARRAY_1 + 1
//                val i = indexOf(aEntry, c, oKey)
//                return if (i < 0) null else aEntry[i].value
//            }
//
//            I_OTHER -> return (m_oContents as Map<K, V>).get(oKey)
//
//            else -> throw IllegalStateException()
//        }
//    }
//
//    /**
//     * Associates the specified value with the specified key in this map.
//     *
//     * @param key    key with which the specified value is to be associated
//     * @param value  value to be associated with the specified key
//     *
//     * @return previous value associated with specified key, or <tt>null</tt>
//     * if there was no mapping for key
//     */
//    fun put(key: K, value: V): V? {
//        when (m_nImpl) {
//            I_EMPTY -> {
//                m_oContents = instantiateEntry(key, value)
//                m_nImpl = I_SINGLE.toByte()
//                return null
//            }
//
//            I_SINGLE -> {
//                val entry = m_oContents as Map.Entry<K, V>
//                val entryKey: K? = entry.key
//                var prevValue: V? = null
//                if (equals<K?>(key, entryKey)) {
//                    prevValue = entry.value
//                    entry.value=(value)
//                } else {
//                    // grow to array implementation
//                    val aEntry= arrayOfNulls<Map.Entry<K,V>>(THRESHOLD)
//                    aEntry[0] = entry
//                    aEntry[1] = instantiateEntry(key, value)
//
//                    m_nImpl = I_ARRAY_2.toByte()
//                    m_oContents = aEntry
//                }
//
//                return prevValue
//            }
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> {
//                // "Entry[]" implementation
//                val nImpl = m_nImpl.toInt()
//                val aEntry = m_oContents as Array<Map.Entry<K,V>>
//                val c = nImpl - I_ARRAY_1 + 1
//                var i = indexOf(aEntry, c, key)
//                if (i >= 0) {
//                    val entry = aEntry[i]
//                    val prevValue = entry.value
//                    entry.value=(value)
//                    return prevValue
//                }
//
//                // check if adding the object exceeds the "lite" threshold
//                if (c >= THRESHOLD) {
//                    // time to switch to a different map implementation
//                    val map = instantiateMap()
//                    i = 0
//                    while (i < c) {
//                        val entry = aEntry[i]
//                        map.put(entry.key, entry.value)
//                        ++i
//                    }
//                    map.put(key, value)
//
//                    m_nImpl = I_OTHER.toByte()
//                    m_oContents = map
//                } else {
//                    // use the next available element in the array
//                    aEntry[c] = instantiateEntry(key, value)!!
//                    m_nImpl = (nImpl + 1).toByte()
//                }
//
//                return null
//            }
//
//            I_OTHER -> return (m_oContents as Map<K, V>).put(key, value)
//
//            else -> throw IllegalStateException()
//        }
//    }
//
//    /**
//     * Removes the mapping for this key from this map if present.
//     * Expensive: updates both the underlying cache and the local cache.
//     *
//     * @param oKey key whose mapping is to be removed from the map
//     *
//     * @return previous value associated with specified key, or <tt>null</tt>
//     * if there was no mapping for key.  A <tt>null</tt> return can
//     * also indicate that the map previously associated <tt>null</tt>
//     * with the specified key, if the implementation supports
//     * <tt>null</tt> values.
//     */
//    fun remove(oKey: Key): V? {
//        when (m_nImpl) {
//            I_EMPTY -> return null
//
//            I_SINGLE -> {
//                val entry = m_oContents as Map.Entry<K?, V?>
//                val entryKey: K? = entry.getKey()
//                var prevValue: V? = null
//                if (equals<Any?>(oKey, entryKey)) {
//                    prevValue = entry.getValue()
//                    m_nImpl = I_EMPTY.toByte()
//                    m_oContents = null
//                }
//                return prevValue
//            }
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> {
//                // "Entry[]" implementation
//                var nImpl = m_nImpl.toInt()
//                val aEntry: Array<Map.Entry<K?, V?>> = m_oContents as Array<Map.Entry>
//                val c = nImpl - I_ARRAY_1 + 1
//                val i = indexOf(aEntry, c, oKey)
//                if (i < 0) {
//                    return null
//                }
//
//                val prevValue: V? = aEntry[i].getValue()
//                if (c == 1) {
//                    m_nImpl = I_EMPTY.toByte()
//                    m_oContents = null
//                } else {
//                    java.lang.System.arraycopy(aEntry, i + 1, aEntry, i, c - i - 1)
//                    aEntry[c - 1] = null
//                    m_nImpl = (--nImpl).toByte()
//                }
//                return prevValue
//            }
//
//            I_OTHER -> {
//                val map = m_oContents as Map<K?, V?>
//                val prevValue: V? = map.remove(oKey)
//                checkShrinkFromOther()
//                return prevValue
//            }
//
//            else -> throw java.lang.IllegalStateException()
//        }
//    }
//
//    /**
//     * Clear all key/value mappings.
//     */
//    fun clear() {
//        m_nImpl = I_EMPTY.toByte()
//        m_oContents = null
//    }
//
//
//    // ----- Cloneable interface --------------------------------------------
//    /**
//     * Create a clone of the ImmutableArrayList.
//     *
//     * @return a clone of this list
//     */
//    public override fun clone(): Any {
//        val that: InflatableMap<*, *>
//        try {
//            that = super.clone() as InflatableMap<*, *>
//        } catch (e: CloneNotSupportedException) {
//            throw ensureRuntimeException(e)
//        }
//
//        when (this.m_nImpl) {
//            I_EMPTY -> {}
//            I_SINGLE -> {
//                val entry: Map.Entry<K?, V?> = m_oContents as Map.Entry
//                that.m_oContents = that.instantiateEntry(entry.getKey(), entry.getValue())
//            }
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> {
//                val aEntryThis: Array<Map.Entry<K?, V?>> = this.m_oContents as Array<Map.Entry>
//                val aEntryThat: Array<Map.Entry<K?, V?>?> = kotlin.arrayOfNulls<Map.Entry>(THRESHOLD)
//                var i = 0
//                val c = m_nImpl - I_ARRAY_1 + 1
//                while (i < c) {
//                    val entryThis = aEntryThis[i]
//                    aEntryThat[i] = that.instantiateEntry(
//                        entryThis.getKey(), entryThis.getValue()
//                    )
//                    ++i
//                }
//                that.m_oContents = aEntryThat
//            }
//
//            I_OTHER -> {
//                val mapThis = this.m_oContents as Map<K?, V?>?
//                val mapThat: Map<K?, V?> = that.instantiateMap()
//                mapThat.putAll(mapThis)
//                that.m_oContents = mapThat
//            }
//
//            else -> throw java.lang.IllegalStateException()
//        }
//
//        return that
//    }
//
//
//    // ----- inner class: EntrySet ------------------------------------------
//    /**
//     * Returns a set view of the mappings contained in this map.  Each element
//     * in the returned set is an [Map Entry][java.util.Map.Entry]. The set is backed by the
//     * map, so changes to the map are reflected in the set, and vice-versa.
//     * If the map is modified while an iteration over the set is in progress
//     * (except by the iterator's own <tt>remove</tt> operation, or by the
//     * <tt>setValue</tt> operation on a map entry returned by the iterator)
//     * the results of the iteration are undefined. The set supports element
//     * removal, which removes the corresponding mapping from the map, via the
//     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, <tt>removeAll</tt>,
//     * <tt>retainAll</tt> and <tt>clear</tt> operations. It is not expected to
//     * support the <tt>add</tt> or <tt>addAll</tt> operations.
//     *
//     * @return a set view of the mappings contained in this map
//     */
//    fun entrySet(): Set<Entry<K?, V?>?>? {
//        return instantiateEntrySet()
//    }
//
//    /**
//     * A Set of entries backed by this Map.
//     */
//    protected inner class EntrySet : AbstractSet<Entry<K?, V?>?>(), Serializable {
//        /**
//         * Returns an iterator over the elements contained in this collection.
//         *
//         * @return an iterator over the elements contained in this collection
//         */
//        fun iterator(): Iterator<Entry<K?, V?>?>? {
//            val map: InflatableMap<K?, V?> = this@InflatableMap
//            val c = map.size()
//            return if (c == 0)
//                NULL_ITERATOR
//            else
//                InflatableMap.EntryIterator<K?, V?>(
//                    map,
//                    (toArray(kotlin.arrayOfNulls<Map.Entry>(c)) as kotlin.Array<Map.Entry<K?, V?>?>?)!!
//                )
//        }
//
//        /**
//         * Returns <tt>true</tt> if this Set is empty.
//         *
//         * @return <tt>true</tt> if this Set is empty
//         */
//        override fun isEmpty(): Boolean {
//            return this@InflatableMap.isEmpty()
//        }
//
//        /**
//         * Returns the number of elements in this collection.
//         *
//         * @return the number of elements in this collection
//         */
//        fun size(): Int {
//            return this@InflatableMap.size
//        }
//
//        /**
//         * Returns <tt>true</tt> if this collection contains the specified
//         * element.  More formally, returns <tt>true</tt> if and only if this
//         * collection contains at least one element <tt>e</tt> such that
//         * <tt>(o==null ? e==null : o.equals(e))</tt>.
//         *
//         *
//         *
//         * @param o object to be checked for containment in this collection
//         *
//         * @return <tt>true</tt> if this collection contains the specified
//         * element
//         */
//        fun contains(o: Any?): Boolean {
//            if (o is Map.Entry) {
//                val entry: Map.Entry = o as Map.Entry
//                val oKey: Any? = entry.getKey()
//                val oValue: Any? = entry.getValue()
//                val map: InflatableMap<*, *> = this@InflatableMap
//                val oActual: Any? = map.get(oKey)
//                return if (oActual == null)
//                    oValue == null && map.containsKey(oKey)
//                else
//                    equals<Any?>(oValue, oActual)
//            }
//
//            return false
//        }
//
//        /**
//         * Returns an array with a runtime type is that of the specified array
//         * and that contains all of the elements in this collection.  If the
//         * collection fits in the specified array, it is returned therein.
//         * Otherwise, a new array is allocated with the runtime type of the
//         * specified array and the size of this collection.
//         *
//         *
//         * If the collection fits in the specified array with room to spare
//         * (i.e. the array has more elements than the collection), the element
//         * in the array immediately following the end of the collection is set
//         * to <tt>null</tt>.  This is useful in determining the length of the
//         * collection *only* if the caller knows that the collection does
//         * not contain any <tt>null</tt> elements.)
//         *
//         * @param ao  the array into which the elements of the collection are
//         * to be stored, if it is big enough; otherwise, a new
//         * array of the same runtime type is allocated for this
//         * purpose
//         *
//         * @return an array containing the elements of the collection
//         *
//         * @throws ArrayStoreException if the runtime type of the specified
//         * array is not a supertype of the runtime type of every
//         * element in this collection
//         */
//        /**
//         * Returns an array containing all of the elements in this collection.
//         *
//         * @return an array containing all of the elements in this collection
//         */
//        @JvmOverloads
//        fun toArray(ao: Array<Any?>? = null as Array<Any?>?): Array<Any?>? {
//            var ao = ao
//            val map: InflatableMap<*, *> = this@InflatableMap
//
//            // create the array to store the map contents
//            val c = map.size()
//            if (ao == null) {
//                ao = if (c == 0) NO_OBJECTS else kotlin.arrayOfNulls<Any>(c)
//            } else if (ao.size < c) {
//                // if it is not big enough, a new array of the same runtime
//                // type is allocated
//                ao = kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType.Array.newInstance(
//                    ao.javaClass.getComponentType(),
//                    c
//                ) as Array<Any?>?
//            } else if (ao.size > c) {
//                // if the collection fits in the specified array with room to
//                // spare, the element in the array immediately following the
//                // end of the collection is set to null
//                ao[c] = null
//            }
//
//            when (map.m_nImpl) {
//                I_EMPTY -> {}
//                I_SINGLE -> ao!![0] = map.m_oContents
//                I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> java.lang.System.arraycopy(
//                    m_oContents as Array<Map.Entry?>?,
//                    0,
//                    ao,
//                    0,
//                    c
//                )
//
//                I_OTHER -> ao = (m_oContents as Map).entrySet().toArray(ao)
//                else -> throw java.lang.IllegalStateException()
//            }
//
//            return ao
//        }
//    }
//
//
//    // ----- Externalizable interface ---------------------------------------
//    /**
//     * Initialize this object from the data in the passed ObjectInput stream.
//     *
//     * @param in  the stream to read data from in order to restore the object
//     *
//     * @exception IOException  if an I/O exception occurs
//     */
//    @Throws(IOException::class, java.lang.ClassNotFoundException::class)
//    fun readExternal(`in`: ObjectInput) {
//        if (!isEmpty()) {
//            throw NotActiveException()
//        }
//
//        val c: Int = `in`.readInt()
//        when (c) {
//            0 -> {}
//            1 -> {
//                m_nImpl = I_SINGLE.toByte()
//                m_oContents = instantiateEntry(`in`.readObject() as K?, `in`.readObject() as V?)
//            }
//
//            2, 3, 4, 5, 6, 7, 8 -> {
//                val aEntry: Array<Map.Entry<K?, V?>?> = kotlin.arrayOfNulls<Map.Entry>(THRESHOLD)
//                var i = 0
//                while (i < c) {
//                    aEntry[i] = instantiateEntry(`in`.readObject() as K?, `in`.readObject() as V?)
//                    ++i
//                }
//                m_nImpl = (I_ARRAY_1 + c - 1).toByte()
//                m_oContents = aEntry
//            }
//
//            else -> {
//                val map = instantiateMap()
//                var i = 0
//                while (i < c) {
//                    map.put(`in`.readObject() as K?, `in`.readObject() as V?)
//                    ++i
//                }
//                m_nImpl = I_OTHER.toByte()
//                m_oContents = map
//            }
//        }
//    }
//
//    /**
//     * Write this object's data to the passed ObjectOutput stream.
//     *
//     * @param out  the stream to write the object to
//     *
//     * @exception IOException if an I/O exception occurs
//     */
//    @Synchronized
//    @Throws(IOException::class)
//    fun writeExternal(out: ObjectOutput) {
//        // format is int size followed by that many key/value pairs
//        val nImpl = m_nImpl.toInt()
//        when (nImpl) {
//            I_EMPTY -> out.writeInt(0)
//            I_SINGLE -> {
//                val entry = m_oContents as Map.Entry<K?, V?>
//                out.writeInt(1)
//                out.writeObject(entry.getKey())
//                out.writeObject(entry.getValue())
//            }
//
//            I_ARRAY_1, I_ARRAY_2, I_ARRAY_3, I_ARRAY_4, I_ARRAY_5, I_ARRAY_6, I_ARRAY_7, I_ARRAY_8 -> {
//                val aEntry: Array<Map.Entry<K?, V?>> = m_oContents as Array<Map.Entry>
//                val c = nImpl - I_ARRAY_1 + 1
//                out.writeInt(c)
//                var i = 0
//                while (i < c) {
//                    val entry = aEntry[i]
//                    out.writeObject(entry.getKey())
//                    out.writeObject(entry.getValue())
//                    ++i
//                }
//            }
//
//            I_OTHER -> {
//                val map = (m_oContents as Map<K?, V?>)
//                val c: Int = map.size()
//                val aEntry: Array<Map.Entry<K?, V?>> =
//                    map.entrySet().toArray(kotlin.arrayOfNulls<Map.Entry>(c)) as Array<Map.Entry>
//                out.writeInt(c)
//                var i = 0
//                while (i < c) {
//                    val entry = aEntry[i]
//                    out.writeObject(entry.getKey())
//                    out.writeObject(entry.getValue())
//                    ++i
//                }
//            }
//
//            else -> throw java.lang.IllegalStateException()
//        }
//    }
//
//    // ----- internal methods -----------------------------------------------
//    /**
//     * (Factory pattern) Instantiate a Map Entry.
//     * This method permits inheriting classes to easily override the
//     * implementation of the Entry object.
//     *
//     * @param key    the key
//     * @param value  the value
//     *
//     * @return an instance of a Map Entry
//     */
//    protected fun instantiateEntry(key: K, value: V): Map.Entry<K, V> {
//        return SimpleEntry(key, value)
//    }
//
//    /**
//     * (Factory pattern) Instantiate an Entry Set.
//     * This method permits inheriting classes to easily override the
//     * implementation of the EntrySet object.
//     *
//     * @return an instance of Entry Set
//     */
//    protected fun instantiateEntrySet(): Set<Entry<K?, V?>?>? {
//        return InflatableMap.EntrySet()
//    }
//
//    /**
//     * (Factory pattern) Instantiate a Map object to store entries in once
//     * the "lite" threshold has been exceeded. This method permits inheriting
//     * classes to easily override the choice of the Map object.
//     *
//     * @return an instance of Map
//     */
//    protected fun instantiateMap(): Map<K, V> {
//        return HashMap()
//    }
//
//    /**
//     * Scan up to the first <tt>c</tt> elements of the passed Entry array
//     * <tt>aEntry</tt> looking for the specified key <tt>key</tt>. If it is
//     * found, return its position <tt>i</tt> in the array such that
//     * <tt>(0 &lt;= i &lt; c)</tt>. If it is not found, return <tt>-1</tt>.
//     *
//     * @param aEntry  the array of objects to search
//     * @param c       the number of Entry objects in the array to search
//     * @param oKey    the key to look for
//     *
//     * @return the index of the object, if found; otherwise -1
//     */
//    private fun indexOf(aEntry: Array<Map.Entry<K?, V?>>, c: Int, oKey: Any?): Int {
//        // first quick-scan by reference
//        for (i in 0..<c) {
//            if (oKey === aEntry[i].getKey()) {
//                return i
//            }
//        }
//
//        // slow scan by equals()
//        if (oKey != null) {
//            for (i in 0..<c) {
//                if (oKey == aEntry[i].getKey()) {
//                    return i
//                }
//            }
//        }
//
//        return -1
//    }
//
//    /**
//     * Return the specified exception as a RuntimeException, wrapping it if necessary.
//     *
//     * @param t  the exception
//     *
//     * @return the RuntimeException
//     */
//    protected fun ensureRuntimeException(t: Throwable): RuntimeException {
//        return if (t is RuntimeException)
//            t as RuntimeException
//        else
//            RuntimeException(t)
//    }
//
//    /**
//     * After a mutation operation has reduced the size of an underlying Map,
//     * check if the delegation model should be replaced with a more size-
//     * efficient storage approach, and switch accordingly.
//     */
//    protected fun checkShrinkFromOther() {
//        assert(m_nImpl.toInt() == I_OTHER)
//
//        // check if the Map is now significantly below the "lite"
//        // threshold
//        val map: Map<K?, V?> = m_oContents as Map
//        val c: Int = map.size()
//        when (c) {
//            0 -> {
//                m_nImpl = I_EMPTY.toByte()
//                m_oContents = null
//            }
//
//            1 -> {
//                val entry: Map.Entry<K?, V?> = map.entrySet().toArray()[0] as Map.Entry
//                m_oContents = instantiateEntry(entry.getKey(), entry.getValue())
//                m_nImpl = I_SINGLE.toByte()
//            }
//
//            2, 3, 4 -> {
//                // shrink to "Entry[]" implementation
//                val aEntry: Array<Map.Entry<K?, V?>?> = kotlin.arrayOfNulls<Map.Entry>(THRESHOLD)
//                var i = 0
//                val iter: Iterator = map.entrySet().iterator()
//                while (iter.hasNext()) {
//                    val entry: Map.Entry<K?, V?> = iter.next() as Map.Entry
//                    aEntry[i++] = instantiateEntry(entry.getKey(), entry.getValue())
//                }
//                assert(i == c)
//
//                m_nImpl = (I_ARRAY_1 + i - 1).toByte()
//                m_oContents = aEntry
//            }
//        }
//    }
//
//
//    // ----- inner class: EntryIterator -------------------------------------
//    /**
//     * A simple Iterator for InflatableMap Entry objects. This class is static in
//     * order to allow the EntrySet to be quickly garbage-collected.
//     */
//    class EntryIterator<K, V>
//        (map: InflatableMap<K?, V?>, aEntry: Array<Map.Entry<K?, V?>?>) : Iterator<Entry<K?, V?>?> {
//        // ----- Iterator interface -------------------------------------
//        /**
//         * Returns <tt>true</tt> if the iteration has more elements.
//         * (In other words, returns <tt>true</tt> if <tt>next</tt>
//         * would return an element rather than throwing an exception.)
//         *
//         * @return <tt>true</tt> if the iterator has more elements
//         */
//        fun hasNext(): Boolean {
//            return m_iPrev + 1 < m_aEntry.size
//        }
//
//        /**
//         * Returns the next element in the iteration.
//         *
//         * @return the next element in the iteration
//         *
//         * @exception NoSuchElementException iteration has no more
//         * elements
//         */
//        fun next(): Entry<K?, V?>? {
//            val iNext = m_iPrev + 1
//            if (iNext < m_aEntry.size) {
//                m_iPrev = iNext
//                m_fCanRemove = true
//                return m_aEntry[iNext]
//            } else {
//                throw NoSuchElementException()
//            }
//        }
//
//        /**
//         * Removes from the underlying set the last element
//         * returned by the iterator.  This method can be called only once
//         * per call to <tt>next</tt>.  The behavior of an iterator is
//         * unspecified if the underlying set is modified while the
//         * iteration is in progress in any way other than by calling this
//         * method.
//         *
//         * @exception IllegalStateException if the <tt>next</tt> method
//         * has not yet been called, or the <tt>remove</tt>
//         * method has already been called after the last call
//         * to the <tt>next</tt> method
//         */
//        fun remove() {
//            if (m_fCanRemove) {
//                m_fCanRemove = false
//                m_map.remove(m_aEntry[m_iPrev].getKey())
//            } else {
//                throw IllegalStateException()
//            }
//        }
//
//        // ----- data members -------------------------------------------
//        /**
//         * The InflatableMap. Having this field allows the EntrySet to be
//         * quickly collected by a GC, because the EntryIterator does not
//         * have to maintain a reference to it in order to get to the InflatableMap.
//         */
//        var m_map: Map<K?, V?>
//
//        /**
//         * The entries to iterate.
//         */
//        var m_aEntry: Array<Map.Entry<K?, V?>?>
//
//        /**
//         * The previous index iterated.
//         */
//        var m_iPrev: Int = -1
//
//        /**
//         * True if the previously iterated element can be removed.
//         */
//        var m_fCanRemove: Boolean = false
//        // ----- constructors -------------------------------------------
//        /**
//         * Construct an EntryIterator.
//         *
//         * @param map     the InflatableMap to delegate <tt>remove()</tt> calls to
//         * @param aEntry  the array of Map Entry objects to iterate
//         */
//        init {
//            m_map = map
//            m_aEntry = aEntry
//        }
//    }
//
//
//    // ----- data members ---------------------------------------------------
//    /**
//     * Implementation, one of I_EMPTY, I_SINGLE, I_ARRAY_* or I_OTHER.
//     */
//    protected var m_nImpl: Int = 0
//
//    /**
//     * The Map contents, based on the implementation being used.
//     */
//    protected var m_oContents: Any? = null
//
//    companion object {
//        // ----- constants ------------------------------------------------------
//        /**
//         * Serial version UID.
//         */
//        private val serialVersionUID = -4252475545246687924L
//
//        /**
//         * A constant array of zero size.  (This saves having to allocate what
//         * should be a constant.)
//         */
//        private val NO_OBJECTS = kotlin.arrayOfNulls<Any>(0)
//
//        /**
//         * The default point above which the InflatableMap delegates to another Map
//         * implementation.
//         */
//        protected const val THRESHOLD: Int = 8
//
//        /**
//         * Implementation:  Empty Map.
//         */
//        private const val I_EMPTY = 0
//
//        /**
//         * Implementation:  Single-item Map.
//         */
//        private const val I_SINGLE = 1
//
//        /**
//         * Implementation:  Array Map of 1 item.
//         */
//        private const val I_ARRAY_1 = 2
//
//        /**
//         * Implementation:  Array Map of 2 items.
//         */
//        private const val I_ARRAY_2 = 3
//
//        /**
//         * Implementation:  Array Map of 3 items.
//         */
//        private const val I_ARRAY_3 = 4
//
//        /**
//         * Implementation:  Array Map of 4 items.
//         */
//        private const val I_ARRAY_4 = 5
//
//        /**
//         * Implementation:  Array Map of 5 items.
//         */
//        private const val I_ARRAY_5 = 6
//
//        /**
//         * Implementation:  Array Map of 6 items.
//         */
//        private const val I_ARRAY_6 = 7
//
//        /**
//         * Implementation:  Array Map of 7 items.
//         */
//        private const val I_ARRAY_7 = 8
//
//        /**
//         * Implementation:  Array Map of 8 items.
//         */
//        private const val I_ARRAY_8 = 9
//
//        /**
//         * Implementation:  Delegation.
//         */
//        protected const val I_OTHER: Int = 10
//
//        /**
//         * An empty iterator.
//         */
//        private val NULL_ITERATOR = object : Iterator<Any>() {
//            public override fun hasNext(): Boolean {
//                return false
//            }
//
//            public override fun next(): Any? {
//                throw NoSuchElementException()
//            }
//        }
//    }
//}
